//
//  MainTableHeaderView.m
//  BigTyre
//
//  Created by 田涛 on 2017/3/26.
//  Copyright © 2017年 Lemon. All rights reserved.
//

#import "MainTableHeaderView.h"

#import <SDAutoLayout.h>

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define IMGWIDTH 25
@interface MainTableHeaderView ()
@property (nonatomic, strong) UIView *view;
@property (nonatomic, strong) UIImageView *img;
@property (nonatomic, strong) UILabel *titleLbl;
@property (nonatomic, assign) CGSize size;
@end

@implementation MainTableHeaderView

- (instancetype)initWithFrame:(CGRect)frame image:(NSString *)img title:(NSString *)title {
    if (self = [super initWithFrame:frame]) {
        [self initViewsWithimage:img title:title];
        [self layoutVies];
    }
    return self;
}

- (void)initViewsWithimage:(NSString *)img title:(NSString *)title {
    _view = [[UIView alloc] init];
    [self addSubview:self.view];
    
    _img = [[UIImageView alloc] init];
    _img.image = [UIImage imageNamed:img];
    [_view addSubview:self.img];
    
    UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:17.0f];
    _titleLbl = [[UILabel alloc] init];
    _titleLbl.font =  font;
    _titleLbl.text = title;
    _size = [_titleLbl.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName, nil]];
    [_view addSubview:self.titleLbl];
}

- (void)layoutVies {
    
    _view.sd_layout
    .topEqualToView(self)
    .centerXEqualToView(self)
    .widthIs(IMGWIDTH + 10 + _size.width)
    .bottomEqualToView(self);
    
    _img.sd_layout
    .topSpaceToView(_view,10)
    .leftEqualToView(_view)
    .widthIs(IMGWIDTH)
    .bottomSpaceToView(_view,10);
    
    _titleLbl.sd_layout
    .topEqualToView(_img)
    .leftSpaceToView(_img,10)
    .widthIs(_size.width)
    .bottomSpaceToView(_view,10);
    
}

@end
